package com.forenow.demo;

import java.util.Scanner;

public class demo1 {
    String number="test";
    String password="test";
    double money=10000;
    public static void main(String[] args) {
        demo1 dm=new demo1();
        menu();
        dm.login();
    }
    /**
     * 菜单
     */
    public static void menu(){
        System.out.println("*******      欢迎登陆    ********");
        System.out.println("*******   中国人民银行   ********");
        System.out.println("*******************版本1.0  *****");
        System.out.println("---------------------------------");
    }
    /**
     * login
     */
    public  void login(){
        Scanner sc = new Scanner(System.in);
        out:for(int i=1;i<=3;i++){
            System.out.println("请输入账号：");
            String num =sc.next();
            System.out.println("请输入密码：");
            String ps=sc.next();
            if (num.equals(number)&&ps.equals(password)){
                System.out.println("登录成功！");
                System.out.println("1.查询余额  2.存款  3.取款  4.修改密码  5.退出");
                caozuo();
                break out;
            }else{
                System.out.println("登录失败！");
                System.out.println("今日还剩"+(3-i)+"次");
            }if(3-i==0){
                System.out.println("错误次数为3次，吞卡，请找工作人员帮忙");
            }
        }

    }
    /**
     * 功能
     */
    public void caozuo() {
        Scanner sc = new Scanner(System.in);
            System.out.println("请选择操作");
            int i = sc.nextInt();
            switch (i) {
                case 1:
                    System.out.println("余额为"+money);
                    break ;
                case 2:
                    System.out.println("请输入存款额度");
                    double inmoney = sc.nextDouble();
                    if(inmoney<0||inmoney%100!=0){
                        System.out.println("存款不合法");
                    }else{
                        money+=inmoney;
                    }
                    break;
                case 3:
                    System.out.println("请输入取款额度");
                    double outmoney =sc.nextDouble();
                    if (outmoney>money){
                        System.out.println("余额不足");
                    }else if (outmoney<0||outmoney>10000||outmoney%100!=0){
                        System.out.println("取款不合法");
                    }else{
                        money-=outmoney;
                }
                    break;
                case 4:
                    System.out.println("请输入原密码");
                    String pw = sc.next();
                    if (pw.equals(password)){
                        System.out.println("请输入新密码：");
                        String newpw = sc.next();
                        System.out.println("请再一次输入新密码：");
                        String repw = sc.next();
                        if (repw.equals(newpw)) {
                            password=newpw;
                            System.out.println("密码修改成功");
                        }else {
                            System.out.println("两次密码修改不一致"+"当前密码是"+password);
                        }
                        login();
                    }else{
                        System.out.println("原密码错误不能修改！");
                    }
                    break;
                default:
                    System.exit(0);
                    break;
        }
        choose();
    }
    /**
     * 判断是否执行
     */
    public void choose(){
        Scanner sc = new Scanner(System.in);
        System.out.println("是否继续执行");
        String  key = sc.next();
        while (key.equals("y")) {
            System.out.println("1.查询余额  2.存款  3.取款  4.修改密码  5.退出");
            caozuo();
        }
    }
}
